package cn.com.nes.site.controller.design;

import cn.com.nes.mybatis.agent.templatedesign.entity.HDevicemodel;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.design.deviceModelVo;
import cn.com.nes.site.service.templatedesign.HDevicemodelService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 测试用
 */
@Controller
@RequestMapping("/v2/DeviceModel")
public class DeviceModelController {
    @Autowired
    HDevicemodelService hDevicemodelService;

    /**
     * 修改设备模板
     * @param hDevicemodel
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "/updateDeviceModel")
    @ResponseBody
    public PageData updateDeviceModel(@RequestBody HDevicemodel hDevicemodel) throws Exception{
        int count=hDevicemodelService.updateDeviceModel(hDevicemodel);
        if (count==0){
            PageData.error("编辑操作失败!");
        }
        return PageData.ok();
    }

    /**
     * 添加设备模板
     * @param hDevicemodel
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "/addDeviceModel")
    @ResponseBody
    public PageData addDeviceModel(@RequestBody HDevicemodel hDevicemodel)throws Exception{
        int count=hDevicemodelService.addDeviceModel(hDevicemodel);
        if (count==0){
            PageData.error("添加操作失败!");
        }
        return PageData.ok();
    }

    /**
     * 删除设备模板
     * @param hDevicemodel
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "/deleteDeviceModel")
    @ResponseBody
    public PageData deleteDeviceModel(@RequestBody HDevicemodel hDevicemodel) throws Exception{
        int count=hDevicemodelService.deleteDeviceModelById(hDevicemodel);
        if (count==0){
            PageData.error("添加操作失败!");
        }
        return PageData.ok();
    }

//    /**
//     * 查询设备型号id和设备型号名字
//     * @param hDevicemodel
//     * @return
//     */
//    @RequestMapping(method = RequestMethod.POST,value = "/selectSbxhIdAndName")
//    @ResponseBody
//    public PageData selectSbxhIdAndName(@RequestBody HDevicemodel hDevicemodel)  {
//       List<Map<String,Object>>list=hDevicemodelService.selectSbxhIdAndName(hDevicemodel);
//        return PageData.ok(list);
//    }

    /**
     * 查询设备模板
     * @param modelVo
     * @return
     * @throws Exception
     */
    @RequestMapping(method = RequestMethod.POST,value = "/selectSbxhIdAndName")
    @ResponseBody
    public PageData selectDeviceModel(@RequestBody deviceModelVo modelVo)throws Exception{
       Page<Map<String,Object>> page=hDevicemodelService.selectDeviceModel(modelVo);

        return PageData.ok(page);
    }

    }
